package com.javasix;

public class MaiQ implements Runnable {

    private int count=10;
    private int num;

    boolean isflage=true;
    @Override
    public void run() {
        while (true){
            synchronized (this){
                if(count<=0){
                   break;
                }
                try {
                    Thread.sleep(1000);
                    count--;
                    num++;
                    System.out.println(Thread.currentThread().getName()+"抢到第"+num+"张票,剩余"+count+"张票");
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }

   /* public synchronized void site(){
        if(count<=0){
            isflage=false;
            return;
        }
        try {
            Thread.sleep(1000);
            count--;
            num++;
            System.out.println(Thread.currentThread().getName()+"抢到第"+num+"张票,剩余"+count+"张票");
        }catch (Exception e){
            e.printStackTrace();
        }
    }*/
}
